﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Manyor.Client;
using System.IO;
using Manyor.Net;

namespace Manyor.Client
{
    class Program
    {
        static SocketClient sc;
        static void Main(string[] args)
        {
            System.Console.WriteLine("press any key try connect..");
            System.Console.ReadLine();
            sc = new SocketClient();

            FileStream fs = new FileStream("1.jpg",FileMode.Open);
            Console.WriteLine("任意键发送");
            System.Console.ReadLine();
          
            int contentLength = NetConfig.CONTENT_SIZE;
            //计算所需要传输的次数
            int sendTimes = (int)fs.Length / contentLength;
            if (fs.Length > sendTimes * contentLength)
            {
                sendTimes++;
            }
            Console.WriteLine("sendtimes:" + sendTimes);
            for (int i = 0; i < sendTimes ; i++)
            {
                int timeLength = (int)((fs.Length - i * contentLength) / contentLength >= 1 ? contentLength : fs.Length - i * contentLength);
                byte[] bytes = new byte[NetConfig.HEADER_SIZE + timeLength];
                bytes[0] = (byte)((i == sendTimes - 1) ? 1 : 0);
                Console.WriteLine(i );
                fs.Read(bytes, NetConfig.HEADER_SIZE, timeLength);
                sc.SendStream(bytes);
            }
            fs.Close();
            System.Console.ReadLine();
        }
    }
}
